---
title: ThreadRuntime
---

import { ParametersTable } from "@/components/docs";
import { ThreadRuntime, ThreadState } from "@/generated/typeDocs";
import {
  ThreadMessagesState,
  ThreadViewportState,
} from "@/components/docs/parameters/context";

### `useThreadRuntime`

Get the thread runtime object:

```tsx
import { useThreadRuntime } from "@assistant-ui/react";

const thread = useThreadRuntime();
```

<ParametersTable {...ThreadRuntime} />

### `useThread`

Access the thread state directly:

```tsx
import { useThread } from "@assistant-ui/react";

const thread = useThread();
const isRunning = useThread((m) => m.isRunning);
```

<ParametersTable {...ThreadState} />

### `useThreadMessages`

Work with the messages within a thread:

```tsx
import { useThreadMessages } from "@assistant-ui/react";

const messages = useThreadMessages();
const firstMessage = useThreadMessages((m) => m[0]);
```

<ParametersTable {...ThreadMessagesState} />

### `useThreadViewport`

Manage thread viewport state (e.g., scrolling):

```tsx
import { useThreadViewport } from "@assistant-ui/react";

const threadViewport = useThreadViewport();
const isAtBottom = useThreadViewport((m) => m.isAtBottom);
```

<ParametersTable {...ThreadViewportState} />
